2 // ValidationMethodsTest.m
5 // Copyright (c) 2020 Apple Inc. All rights reserved.
8 #import <XCTest/XCTest.h>
9 #include "dnssec_v2_crypto.h"
10 #include "mDNSEmbeddedAPI.h"
11 #if MDNSRESPONDER_SUPPORTS(APPLE, DNSSECv2)
13 @interface CanonicalMethodsTest : XCTestCase
17 @implementation CanonicalMethodsTest
19 - (void)test_copy_canonical_name {
20 mDNSu8 canonical_name[MAX_DOMAIN_NAME];
23 mDNSu8 name_1[MAX_DOMAIN_NAME] = {
27 'a', 'p', 'p', 'l', 'e',
32 mDNSu8 name_1_after_conversion[MAX_DOMAIN_NAME] = {
36 'a', 'p', 'p', 'l', 'e',
42 for (unsigned long i = 15; i < sizeof(name_1); i++) {
47 name_length = copy_canonical_name_ut(canonical_name, name_1);
48 XCTAssertEqual(name_length, DomainNameLength((domainname *)name_1_after_conversion));
49 XCTAssert(memcmp(canonical_name, name_1_after_conversion, name_length) == 0);
52 - (void)test_compare_canonical_dns_name {
53 const unsigned char inputs[][256] = {
54 {7, 'e', 'x', 'a', 'm', 'p', 'l', 'e', 0}, // example.
55 {1, 'a', 7, 'e', 'x', 'a', 'm', 'p', 'l', 'e', 0}, // a.example.
56 {8, 'y', 'l', 'j', 'k', 'j', 'l', 'j', 'k', 1, 'a', 7, 'e', 'x', 'a', 'm', 'p', 'l', 'e', 0}, // yljkjljk.a.example.
57 {1, 'Z', 1, 'a', 7, 'e', 'x', 'a', 'm', 'p', 'l', 'e', 0}, // Z.a.example.
58 {4, 'z', 'A', 'B', 'C', 1, 'a', 7, 'E', 'X', 'A', 'M', 'P', 'L', 'E', 0}, // zABC.a.EXAMPLE.
59 {1, 'z', 7, 'e', 'x', 'a', 'm', 'p', 'l', 'e', 0}, // z.example.
60 {1, 1 , 1, 'z', 7, 'e', 'x', 'a', 'm', 'p', 'l', 'e', 0}, // \001.z.example.
61 {1, '*', 1, 'z', 7, 'e', 'x', 'a', 'm', 'p', 'l', 'e', 0}, // *.z.example
62 {1, 200, 1, 'z', 7, 'e', 'x', 'a', 'm', 'p', 'l', 'e', 0} // \200.z.example.
65 for (size_t i = 0; i < sizeof(inputs) / 256; i++) {
66 for (size_t j = 0; j < sizeof(inputs) / 256; j++) {
68 XCTAssertTrue(compare_canonical_dns_name(inputs[i], inputs[j]) < 0);
70 XCTAssertTrue(compare_canonical_dns_name(inputs[i], inputs[j]) > 0);
72 XCTAssertTrue(compare_canonical_dns_name(inputs[i], inputs[j]) == 0);
79 #endif // MDNSRESPONDER_SUPPORTS(APPLE, DNSSECv2)